package jobs;

// 基础咖啡类
abstract class Coffee {
    public abstract double cost();
}

// 具体咖啡类
class SimpleCoffee extends Coffee {
    @Override
    public double cost() {
        return 10.0; // 基础咖啡价格
    }
}

// 抽象装饰器
abstract class CoffeeDecorator extends Coffee {
    protected Coffee coffee;
    public CoffeeDecorator(Coffee coffee) {
        this.coffee = coffee;
    }
}

// 牛奶装饰器
class MilkDecorator extends CoffeeDecorator {
    public MilkDecorator(Coffee coffee) {
        super(coffee);
    }
    @Override
    public double cost() {
        return coffee.cost() + 3.0; // 牛奶加3元
    }
}

// 巧克力装饰器
class ChocolateDecorator extends CoffeeDecorator {
    public ChocolateDecorator(Coffee coffee) {
        super(coffee);
    }
    @Override
    public double cost() {
        return coffee.cost() + 5.0; // 巧克力加5元
    }
}

// 测试类
public class CoffeeDecoratorTest {
    public static void main(String[] args) {
        Coffee coffee = new SimpleCoffee();
        System.out.println("原味咖啡价格: " + coffee.cost());

        Coffee milkCoffee = new MilkDecorator(coffee);
        System.out.println("加牛奶咖啡价格: " + milkCoffee.cost());

        Coffee chocoMilkCoffee = new ChocolateDecorator(milkCoffee);
        System.out.println("加牛奶和巧克力咖啡价格: " + chocoMilkCoffee.cost());
    }
}
